package com.ruoyi.my.controller.courseplan;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.my.domian.courseplan.CoursePlanCategoryVO;
import com.ruoyi.my.service.courseplan.CoursePlanCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseplan/category")
public class CoursePlanCategoryController extends BaseController {

    @Autowired
    private CoursePlanCategoryService coursePlanCategoryService;

    /**
     * 获取课程列表
     */
    @PreAuthorize("@ss.hasPermi('courseplan:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoursePlanCategoryVO coursePlanCategoryVO) {
        startPage();
        List<CoursePlanCategoryVO> list = coursePlanCategoryService.selectCoursePlanCategoryList(coursePlanCategoryVO);
        return getDataTable(list);
    }

    /**
     * 删除课程
     */
    @PreAuthorize("@ss.hasPermi('courseplan:category:delete')")
    @DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds) {
        return toAjax(coursePlanCategoryService.deleteCoursePlanCategoryByIds(categoryIds));
    }

    /**
     * 修改用户
     */
    @PreAuthorize("@ss.hasPermi('courseplan:category:update')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CoursePlanCategoryVO coursePlanCategoryVO) {
        return toAjax(coursePlanCategoryService.updateCoursePlanCategoryById(coursePlanCategoryVO));
    }

    @PreAuthorize("@ss.hasPermi('courseplan:category:add')")
    @PostMapping
    public AjaxResult addCoursePlanCategory(@Validated @RequestBody CoursePlanCategoryVO coursePlanCategoryVO) {
        return toAjax(coursePlanCategoryService.addCoursePlanCategory(coursePlanCategoryVO));
    }


}
